import Vue from "vue";
import { Loading } from "element-ui";

let loadOn;
let loadingCount = 0;
function startLoading(target) {
  const options = {
    lock: true,
    text: "Loading...",
    spinner: "el-icon-loading",
    target: document.querySelector(target),//target
  };
  loadOn = Loading.service(options);
  return loadOn;
}

function endLoading() {
  loadOn.close();
}

export function showLoading(target) {
  if (loadingCount=== 0) {
    startLoading(target);
  }
  loadingCount++;
}
export function hideLoading() {
  if (loadingCount<= 0) return;
  loadingCount--;
  if (loadingCount=== 0) {
    endLoading();
  }
}